package com.game4U.Component.FlvPlayerComponent
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author Feng
	 */
	public class FlvSkin extends Sprite 
	{
		private var isSoundOn = true;
		public function FlvSkin() 
		{
			this.addEventListener(Event.REMOVED_FROM_STAGE, clear);
			this["playBtn"].addEventListener(MouseEvent.CLICK, onPlayBtnClickHandler);
			this["pauseBtn"].addEventListener(MouseEvent.CLICK, onPauseBtnClickHandler);
			this["sound_btn"].addEventListener(MouseEvent.CLICK, onSoundBtnClickHandler);
			
		}
		
		private function onSoundBtnClickHandler(evt:MouseEvent) {
			if (isSoundOn) {
				this["sound_btn"].gotoAndStop(1);
				dispatchEvent(new Event("FLV_STOP_SOUND_EVENT", true, true));
			}else {
				this["sound_btn"].play();
				dispatchEvent(new Event("FLV_PLAY_SOUND_EVENT", true, true));
			}
			isSoundOn = !isSoundOn;
		}
		
		private function clear(evt:Event) {
			this.removeEventListener(Event.REMOVED_FROM_STAGE, clear);
			this["playBtn"].removeEventListener(MouseEvent.CLICK, onPlayBtnClickHandler);
			this["pauseBtn"].removeEventListener(MouseEvent.CLICK, onPauseBtnClickHandler);
			this["sound_btn"].addEventListener(MouseEvent.CLICK, onSoundBtnClickHandler);
		}
		
		public function SetProgress(progress:Number) {
			this["progessBar"].SetProgress(progress);
		}
		
		public function PlayFLV() {
			this["playBtn"].visible = true;
			this["pauseBtn"].visible = false;
		}
		
		public function Pause() {
			this["playBtn"].visible = false;
			this["pauseBtn"].visible = true;
		}
		
		
		private function onPlayBtnClickHandler(evt:MouseEvent) {
			Pause();
			dispatchEvent(new Event("FLV_PLAY_EVENT", true, true));
		}
		
		private function onPauseBtnClickHandler(evt:MouseEvent) {
			PlayFLV();
			dispatchEvent(new Event("FLV_PAUSE_EVENT", true, true));
		}
		
	}

}